package com.fire8.dolphin.web;


/**
 * <一句话功能简介><br>
 * <功能详细描述>
 *
 * @author  lixg
 * @version [版本号,2012-8-25]
 * @see     [相关类/方法]
 * @since   [产品/模块]
 */
public class WebServiceUtils
{
//    private final String TAG = "dolphin";
//    
//    //命名空间
//    //final static String SERVICE_NS = "http://webService.service.sl.xidian/";
//    final static String SERVICE_NS = "http://WebXml.com.cn/";
//    
//    //定义webservice提供服务的URL 
//    //final static String SERVICE_URL = "http://localhost:8080/dolphin/services/test";
//    final static String SERVICE_URL = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx";
//    
//    HttpTransportSE ht;
//    
//    private static String SOAP_ACTION = "http://WebXml.com.cn/getWeatherbyCityName";
//    
//    SoapSerializationEnvelope envelope;
//    
//    SoapObject request;
//    
//    //调用的方法
//    String methodName = "getWeatherbyCityName";
//    
//    public WebServiceUtils()
//    {
//        //创建httpTransportSE传输对象
//        ht = new HttpTransportSE(SERVICE_URL);
//        //使用soap1.1协议创建Envelop对象
//        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//        
//    }
//    
//    /**
//     * 上传用户信息
//     * 用户第一次打开软件时，将用户信息上传到服务器
//     * @param userInfo
//     * @return [参数说明]
//     *
//     * @author lixg
//     * @see [类、类#方法、类#成员]
//     */
//    public String submitUserInfo(UserInfo userInfo)
//    {
//        String userId=null;
//        //实例化SoapObject对象
//        request = new SoapObject(SERVICE_NS, "submitUserInfo");
//        //设置参数，参数名不一定需要跟调用的服务器端的参数名相同，只需要对应的顺序相同即可
//        request.addProperty("mobile", userInfo.getAccount());
//        request.addProperty("mac", userInfo.getPassword());
//        request.addProperty("location", userInfo.getAddress());
//        
//        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
//        envelope.bodyOut = request;
//        try
//        {
//            ht.call(null, envelope);
//            SoapObject result = (SoapObject)envelope.getResponse();
//            if (result != null)
//            {
//                //返回用户ID
//                userId = result.getProperty(0).toString();
//                
//            }
//        }
//        catch (Exception e)
//        {
//            Log.e(TAG, "" ,e);
//        }
//        return userId;
//    }
//    
//    public void login(UserInfo userInfo)
//    {
//        //实例化SoapObject对象
//        request = new SoapObject(SERVICE_NS, methodName);
//        /**
//         * 设置参数，参数名不一定需要跟调用的服务器端的参数名相同，只需要对应的顺序相同即可
//         * */
//        request.addProperty("account", userInfo.getAccount());
//        request.addProperty("password", userInfo.getPassword());
//        request.addProperty("mobile", userInfo.getAccount());
//        request.addProperty("mac", userInfo.getPassword());
//        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
//        envelope.bodyOut = request;
//        envelope.setOutputSoapObject(request);
//        try
//        {
//            ht.call(null, envelope);
//            SoapObject result = (SoapObject)envelope.getResponse();
//            if (result != null)
//            {
//                
//                String name = result.getProperty(0).toString();
//            }
//        }
//        catch (Exception e)
//        {
//            Log.e(TAG, "" ,e);
//        }
//        
//    }
//    
//    public String submitQuestion(Question question)
//    {
//        String remoteId=null;
//        request = new SoapObject(SERVICE_NS, "submitQuestion");
//        //设置参数，参数名不一定需要跟调用的服务器端的参数名相同，只需要对应的顺序相同即可
//        request.addProperty("title", question.getTitle());
//        request.addProperty("context",question.getContext());
//        request.addProperty("userId", question.getUserId());
//        
//        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
//        envelope.bodyOut = request;
//        try
//        {
//            ht.call(null, envelope);
//            SoapObject result = (SoapObject)envelope.getResponse();
//            if (result != null)
//            {
//                //返回用户ID
//                remoteId = result.getProperty(0).toString();
//            }
//        }
//        catch (Exception e)
//        {
//            Log.e(TAG, "" ,e);
//        }
//        return remoteId;
//    }
//    /**
//     * 取问题列表
//     * 
//     * @param remoteId 当前最大或最小的ID
//     * @param operation 向上或是向下，取当前ID之前的或之后的数据[1：向上(>remoteId)；0：向下]
//     * @param userId [参数说明]
//     *
//     * @author lixg
//     * @see [类、类#方法、类#成员]
//     */
//    public List<Question> getQuestionList(Integer remoteId,Integer operation,String userId)
//    {
//        List<Question> list = new ArrayList<Question>();
//        //实例化SoapObject对象
//        request = new SoapObject(SERVICE_NS, "getQuestionList");
//        //设置参数，参数名不一定需要跟调用的服务器端的参数名相同，只需要对应的顺序相同即可
//        request.addProperty("remoteId", remoteId);
//        request.addProperty("operation", operation);
//        request.addProperty("userId", userId);
//        
//        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
//        envelope.bodyOut = request;
//        try
//        {
//            ht.call(null, envelope);
//            SoapObject result = (SoapObject)envelope.getResponse();
//            if (result != null)
//            {
//                //返回用户ID
//                //userId = result.getProperty(0).toString();
//                
//            }
//        }
//        catch (Exception e)
//        {
//            Log.e(TAG, "", e);
//        }
//        return list;
//    }
//    
//    public void getAnswer(Integer questionId)
//    {
//        //实例化SoapObject对象
//        request = new SoapObject(SERVICE_NS, "getAnswer");
//        //设置参数，参数名不一定需要跟调用的服务器端的参数名相同，只需要对应的顺序相同即可
//        request.addProperty("questionId", questionId);
//                
//        //将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
//        envelope.bodyOut = request;
//        try
//        {
//            ht.call(null, envelope);
//            SoapObject result = (SoapObject)envelope.getResponse();
//            if (result != null)
//            {
//                //返回用户ID
//                //userId = result.getProperty(0).toString();
//            }
//        }
//        catch (Exception e)
//        {
//            Log.e(TAG, "", e);
//        }
//    }
//    
//    public void getWeather(String cityName)
//    {
//        try
//        {
//            Log.d(TAG, "rpc------");
//            SoapObject rpc = new SoapObject(SERVICE_NS, methodName);
//            Log.d(TAG, "rpc" + rpc);
//            Log.d(TAG, "cityName is " + cityName);
//            rpc.addProperty("theCityName", cityName);
//            
//            //SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//            envelope.bodyOut = rpc;
//            envelope.dotNet = true;
//            envelope.setOutputSoapObject(rpc);
//            
//            //HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
//            
//            //AndroidHttpTransport ht = new AndroidHttpTransport(URL);
//            ht.debug = true;
//            
//            ht.call(SOAP_ACTION, envelope);
//            //ht.call(null, envelope);
//            
//            SoapObject result = (SoapObject)envelope.bodyIn;
//            SoapObject detail = (SoapObject)result.getProperty("getWeatherbyCityNameResult");
//            
//            //SoapObject detail =(SoapObject) envelope.getResponse();
//            
//            //System.out.println("result" + result);
//            Log.d(TAG, "detail" + detail);
//            
//            //Toast.makeText(this, detail.toString(), Toast.LENGTH_LONG).show();
//            parseWeather(detail);
//            
//            return;
//        }
//        catch (Exception e)
//        {
//            e.printStackTrace();
//        }
//    }
//    
//    private void parseWeather(SoapObject detail)
//            throws UnsupportedEncodingException
//    {
//        String date = detail.getProperty(6).toString();
//        String weatherToday = "今天：" + date.split(" ")[0];
//        weatherToday = weatherToday + "\n天气：" + date.split(" ")[1];
//        weatherToday = weatherToday + "\n气温："
//                + detail.getProperty(5).toString();
//        weatherToday = weatherToday + "\n风力："
//                + detail.getProperty(7).toString() + "\n";
//        
//        Log.d(TAG, weatherToday);
//        
//    }
}
